package com.apes.hr.base.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
//import com.apes.scm.rbac.model.Post;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Set;

/**
 * 功能：岗位
 *
 * @author HuJianlin
 * @create 2018-04-25 15:11
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = WorkPost.CONST_TABLE_NAME)
public class WorkPost extends Model {
    public static final String CONST_TABLE_NAME = "hr_work_post";

    @Id
    @Column(name = "id", nullable = false, length = 120)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "岗位编码", padding = 7)
    private String id; //岗位编码

    @Name
    @Column(name = "name", nullable = false, length = 200)
    private String name; //岗位名称

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "parents_id", referencedColumnName = "id")
    private WorkPost parents; //直属上级岗位

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "post_group_id", referencedColumnName = "id")
    private WorkPostGroup postGroup; //岗位分组

    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 1")
    private boolean valid = true; //有效

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "price_limit_level", referencedColumnName = "id")
    private Enumeration priLimitLevel; //限价级别

    @Name
    @Column(name = "origin", length = 32)
    private String origin; //外部编码

    public Enumeration getJobFunction() {
        if(postGroup==null) return null;
        return postGroup.getJobFunction();
    }

    @Transient
    private Enumeration jobFunction;


//    @JSONField(serialize = false)
//    @OneToMany(fetch = FetchType.LAZY, mappedBy = "workPost")
//    private Set<Post> posts;

}
